﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BEPUphysics;
using BEPUphysics.DataStructures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using BEPUphysics.Entities;
using PloobsEngine.SceneControl;
using PloobsEngine.Modelo;

namespace PloobsEngine.Physics.Bepu
{
    public class DetectorVolumeObject : IPhysicObject
    {                
        IObject owner;
        TriangleMeshObject mesh;
        DetectorVolume detectorVolume;

        public DetectorVolume DetectorVolume
        {
            get { return detectorVolume; }
            set { detectorVolume = value; }
        }

        public DetectorVolumeObject(TriangleMeshObject mesh) 
        {
            this.mesh = mesh;
            detectorVolume = new DetectorVolume(mesh.TriangleMesh);
        }

        public PhysicObjectTypes PhysicObjectTypes
        {
            get { return PhysicObjectTypes.DETECTOROBJECT; }
        }

        #region IPhysicObject Members

        public Vector3 Position
        {
            get
            {
                return mesh.WorldMatrix.Translation;
            }
            set
            {
                this.mesh.Position = value;
            }
        }

        public Vector3 Scale
        {
            get
            {
                return this.mesh.Scale;
            }
            set
            {
                this.mesh.Scale = value;
            }
        }

        public Matrix Rotation
        {
            get
            {
                return this.mesh.Rotation;
            }
            set
            {
                this.mesh.Rotation = value;
            }
        }

        public Vector3 FaceVector
        {
            get { return this.mesh.FaceVector; }
        }

        public Matrix WorldMatrix
        {
            get { return this.mesh.WorldMatrix; }
        }

        public Vector3 Velocity
        {
            get
            {
                return this.mesh.Velocity;
            }
            set
            {
                this.mesh.Velocity = value;
            }
        }

        public void Serialize(System.Xml.XmlTextWriter textWriter)
        {
            throw new NotImplementedException();
        }

        public void DeSerialize(System.Xml.XmlNode node,EngineStuff engine, IModelo model, Vector3 position, Matrix rotation)
        {
            throw new NotImplementedException();
        }

        public bool isMotionLess
        {
            get
            {
                return this.mesh.isMotionLess;
            }
            set
            {
                this.mesh.isMotionLess = value;
            }
        }

        public IObject ObjectOwner
        {
            get
            {
                return this.mesh.ObjectOwner;
            }
            set
            {
                this.mesh.ObjectOwner = value;
            }
        }

        public void Enable()
        {
            this.mesh.Enable();
        }

        public void Disable()
        {
            this.mesh.Disable();
        }

        public void ApplyImpulse(Vector3 force)
        {
            this.mesh.ApplyImpulse(force);
        }

        public BoundingBox BoundingBox
        {
            get { return this.mesh.BoundingBox; }
        }

        #endregion

        #region IPhysicObject Members


        public void ApplyTorque(Vector3 force)
        {
            this.mesh.ApplyTorque(force);
        }

        #endregion
    }
}
